package com.yunfei.ribbon;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.TimeUnit;

/**
* @Description:  定义一个feign接口，通过@ FeignClient（“服务名”），来指定调用哪个服务。比如在代码中调用了service-hi服务的“/hi”接口，代码如下：
 * Feign中使用断路器：只需要在FeignClient的SchedualServiceHi接口的注解中加上fallback的指定类就行了
* @Author: zhengyunfei q群号:541122375
* @Date: 2018/7/3  
* @time:11:05
*/
@Service
public class RedisServiceRibbon {
    @Autowired
    RestTemplate restTemplate;

    public String get(String key){
        return restTemplate.getForObject("http://APP-REDIS-CENTER/get?key="+key,String.class);
    }

    public boolean exists(String key){
       return restTemplate.getForObject("http://APP-REDIS-CENTER/exists?key="+key,Boolean.class);
    }

    public boolean set( String key, Object value){
        return restTemplate.getForObject("http://APP-REDIS-CENTER/set?key="+key+"&value="+value,Boolean.class);
    }

    public boolean set1( String key,  Object value,  long time){
        return restTemplate.getForObject("http://APP-REDIS-CENTER/set1?key="+key+"&value="+value+"&time="+time,Boolean.class);
    }
    public boolean set2( String key,  Object value,  long time,TimeUnit timeUnit){
        return restTemplate.getForObject("http://APP-REDIS-CENTER/set2?key="+key+"&value="+value+"&time="+time+"&timeUnit="+timeUnit,Boolean.class);
    }
    public boolean getExpireTime( String key,  Object value,  long time){
        return restTemplate.getForObject("http://APP-REDIS-CENTER/getExpireTime?key="+key+"&value="+value+"&time="+time,Boolean.class);
    }

    public boolean remove(String key){
        return restTemplate.getForObject("http://APP-REDIS-CENTER/remove?key="+key,Boolean.class);
    }

}
